﻿using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices;
using Shop.Model.Dto.Block;
using Shop.Model.View.Block;
using System.Text.RegularExpressions;

namespace Shop.WebApi.Controllers;

/// <summary>
/// 用户卡包服务
/// </summary>
[ApiController]
[Route("Api/[controller]")]
public class BlockController: ShopControllerBase
{
    private readonly IBlockAppService _blockAppService;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="blockAppService"></param>
    public BlockController(IBlockAppService blockAppService)
    {
        _blockAppService = blockAppService;
    }

    /// <summary>
    /// 银行卡列表
    /// </summary>
    /// <returns></returns>
    [HttpGet("BlockList")]
    public AppResult<List<BlockListVo>> BlockList()
        => _blockAppService.BlockList();

    /// <summary>
    /// 添加银行卡
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("BlockAdd")]
    public async Task<AppResult> BlockAdd(BlockAddDto dto)
    {
        if (dto.Possessor.Length < 2 || !Regex.IsMatch(dto.Possessor, @"^[\u4e00-\u9fa5]{1,6}(·[\u4e00-\u9fa5]{1,6}){0,2}$"))
            return Problem("请填写正确的姓名");
        return await _blockAppService.BlockAdd(dto);
    }
    
    /// <summary>
    /// 解绑银行卡
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpGet("BlockUntie")]
    public AppResult BlockUntie([FromQuery] long dto)
        => _blockAppService.BlockUntie(dto);
}